package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.StrategyCommend;
import cn.wolfcode.luowowo.article.query.StrategyCommendQuery;
import cn.wolfcode.luowowo.article.service.IStrategyCommendService;
import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.article.service.IStrategyService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/strategyCommend")
public class StrategyCommendController {

   @Reference
   private IStrategyCommendService strategyCommendService;
    @Reference
   private IStrategyService strategyService;
    @Reference
    private IStrategyDetailService strategyDetailService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo")StrategyCommendQuery qo, Model model){
        PageInfo pageInfo = strategyCommendService.query(qo);
        model.addAttribute("pageInfo",pageInfo);

       //查询所有的攻略共享给页面
        model.addAttribute("details",strategyService.selectAll());
        return "strategyCommend/list";
    }


    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyCommend strategyCommend){
        strategyCommendService.saveOrUpdate(strategyCommend);
        return new AjaxResult();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){
        strategyCommendService.delete(id);
        return new AjaxResult();
    }

}
